﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JtextEpicsInterface;

namespace JE_PlugIn_Linear
{
    public class Linear:IJEPlugIn
    {
        #region IJEPlugIn Members

        const string PName = "JEP_Linear";

        public void IniPlugIn(object iniObject, IJERecord record)
        {
            string PlugInProp = (string)iniObject;
            if (PlugInProp.Contains("JEP_Linear"))
            {
                Console.WriteLine("PlugIn Linear Initialed!");
            }
            else
            {
                Console.WriteLine("Linear Not Found in eXtension!");
            }
        }

        public void KillPlugIn()
        {
            throw new NotImplementedException();
        }

        public string PlugInName
        {
            get
            {
                return PName;
            }
        }

        public bool RunPlugIn(IJERecord myRecord)
        {
            double raw = (double)myRecord.VAL;
            double ripe = raw * myRecord.RecordProperty.multilple + myRecord.RecordProperty.offset;
            if (myRecord.RecordProperty.DataType == "DOUBLE")
            {
                myRecord.VAL = ripe;
            }
            else
            {
                myRecord.VAL = Math.Round(ripe);
            }
            Console.WriteLine(myRecord.pvName + " Linearized to " + myRecord.VAL.ToString());
            return true;
        }
        #endregion
    }
}
